<template>
  <div>

    <!--top-->

    <!--msg lists-->
    <template v-if="msgList.imList.length > 0">
      <div v-for="(msgitem,k) in msgList.imList"
           :key="k"
           class="bbf5f6 mt10">
        <MsgBox :msg="msgitem"
                :isImMsg="true"
                :istime="msgitem.newestMessage && msgitem.newestMessage.time"
                @row_tap="row_tap(msgitem.userId || '',msgitem.cardId || '',msgitem.logo || '',msgitem.name || '',msgitem.wxCode || '', msgitem.phone || '')">
        </MsgBox>
      </div>
    </template>
    <div v-else>
      <NoData>暂无消息</NoData>
    </div>
    <div class="textc disflex w60 h60 bradius50p bgblue disinblock back-btn"
         @click="page_turn('usercenter')">
      <img src="https://you-one-stand.oss-cn-shanghai.aliyuncs.com/yimai_photos/user/user_add.png"
           alt=""
           class="w30 h30 mt15">
    </div>
  </div>
</template>

<script>
import NoData from "@/components/noData";
import store from "../../store/index";
import MsgBox from "@/components/msgBox"; // 订单项
import websocket from "../../utils/websocket";
import HandleLogin from "@/utils/handleLogin";
import { authSubscribeMessage } from "../../utils/auth.js";
import { mapGetters } from "vuex";

export default {
  name: "",
  components: { MsgBox, NoData },
  computed: {
    ...mapGetters(["subscriptionNew"])
  },
  data() {
    return {
      page: 1,
      msg_lists: [
        // {
        //     isread:true,
        //     logo:'',
        //     name:'付鑫',
        //     status:'2',
        //     time:'18:20',
        //     text:'您好，我想了解一下壹脉智能名片'
        // },
        // {
        //     logo:'',
        //     name:'付鑫',
        //     status:'1',
        //     time:'18:20',
        //     text:'您好，我想了解一下壹脉智能名片'
        // },
      ]
    };
  },
  /** tab点击 */
  onTabItemTap(item) {
    //订阅授权 信息相关
    authSubscribeMessage(this.subscriptionNew);
  },
  onShow() {
    HandleLogin.isLoginAndShowModal(() => {
      //登录了后查询聊天记录
      websocket.sendSocketJSON("108", this.page);
    });
    if (!wx.getStorageSync("token")) {
      wx.setStorageSync("redirectPage", "/pages/msg/main");
      wx.reLaunch({ url: "/pages/cardCase/main" });
      return;
    }
    //websocket.sendSocketJSON("108",1);
  },
  mounted() {
    wx.setNavigationBarTitle({
      title: "消息"
    });
  },
  computed: {
    msgList() {
      console.debug("store接收的消息+++", store.state.msgList.msglist);
      return store.state.msgList.msglist;
    }
  },
  async onPullDownRefresh() {
    websocket.sendSocketJSON("108", this.page);
    setTimeout(() => {
      wx.stopPullDownRefresh();
    }, 2 * 1000);
  },
  onReachBottom() {
    this.page++;
    websocket.sendSocketJSON("108", this.page);
  },
  methods: {
    page_turn(url) {
      wx.reLaunch({ url: "../" + url + "/main" });
    },
    row_tap(id, cardid, logo, name, wxCode, phone) {
      wx.navigateTo({
        url:
          "../IM/main?userId=" +
          id +
          "&logo=" +
          logo +
          "&type=2&cardId=" +
          cardid +
          "&name=" +
          name +
          "&wxCode=" +
          wxCode +
          "&phone=" +
          phone
      });
    }
  }
};
</script>

<style>
.back-btn {
  position: fixed;
  bottom: 40upx;
  right: 40upx;
}
</style>
